package top.frsf.rpc.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.frsf.rpc.annotations.EnableRpcClient;
import top.frsf.rpc.autoconfigure.proxy.RpcReferenceBeanPostProcessor;
import top.frsf.rpc.registry.ServiceRegistry;
import top.frsf.rpc.session.ClientSessionManager;

/**
 * RPC 客户端自动配置类
 *
 * @author He Kuntao
 * @since 2025/7/9 9:32
 */
@Configuration
@ConditionalOnBean(annotation = EnableRpcClient.class)
public class RpcClientAutoConfiguration {

    /**
     * RPC客户端 @RpcReference 动态代理对象创建后置处理器
     *
     * @return BeanPostProcessor
     */
    @Bean
    public RpcReferenceBeanPostProcessor rpcReferenceBeanPostProcessor(ServiceRegistry registry, ClientSessionManager sessionManager) {
        return new RpcReferenceBeanPostProcessor(registry, sessionManager);
    }

    /**
     * RPC 客户端会话管理器
     *
     * @return ClientSessionManager
     */
    @Bean
    public ClientSessionManager clientSessionManager() {
        return new ClientSessionManager();
    }

}
